<?php
session_start();
@include_once("commonFunctions.php");
?>
<!DOCTYPE HTML>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" type="text/css" href="CSS/formStyle.css" />
    <script language="javascript" type="text/javascript">
        function getXMLHTTP() {
            var xmlhttp=false;
            try{
                xmlhttp=new XMLHttpRequest();
            }
            catch(e)	{
                try{
                    xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch(e){
                    try{
                        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                    }
                    catch(e1){
                        xmlhttp=false;
                    }
                }
            }

            return xmlhttp;
        }

        function getStore(selectedState) {

            var strURL="Javascript/phpHandlers/findStores.php?selectedState="+selectedState;
            var req = getXMLHTTP();

            if (req) {

                req.onreadystatechange = function() {
                    if (req.readyState == 4) {
                        // only if "OK"
                        if (req.status == 200) {
                            document.getElementById('storeDiv').innerHTML=req.responseText;
                        } else {
                            alert("There was a problem while using XMLHTTP:\n" + req.statusText);
                        }
                    }
                }
                req.open("GET", strURL, true);
                req.send(null);
            } else {
                alert("ajax failed");
            }
        }
    </script>
    <title>Cellular Sales - South Georgia TTS - Login</title>
</head>
<body>
    <div id="logo">
	<img src="logo.png" />
    </div>
    <div id="menu">
	<a href="index.php" id="activeitem" class="menuitem">Login</a>
	<p id="districtname">South Georgia</p>
    </div>
    <div id="infobox" class="nongradient">
        <form name="form" id="form" class="form" action="validateLogin.php" method="post" >
	    <table id="logintable">
	    <tr>
	    <td>
            <label for="dealerCode">Dealer Code:</label>
	    </td>
	    <td>
            <input type="text" name="dealerCode" id="dealerCode" />
	    </td>
	    </tr>
	    <tr>
	    <td>
            <label for="market">Market:</label>
	    </td>
	    <td>
            <select name="market" id="market">
                <?php
                $query = 'select distinct market from stores';
                $result = mysql_query($query);
                while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                    echo "<option value = \"{$row['market']}\">{$row['market']}</option>";
                }
                ?>
            </select>
	    </td>
	    </tr>
	    <td>
            <label for="state">State:</label>
	    </td>
	    <td>
            <div id="stateDiv"><select name="state" id="state" onchange="getStore(this.value)">
                    <?php
                    $query = "select distinct state from stores";
                    $result = mysql_query($query);
                    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                        $state = $row['state'];
                        if ($state == 'GA') {
                            echo "<option value = \"$state\" selected = \"$state\" >$state</option>";
                        } else {
                            echo "<option value = \"$state\">$state</option>";
                        }
                    }
                    ?>
                </select></div>
	    </td>
	    </tr>
	    <tr>
	    <td>
            <label for="storeAbbrev">Store Location:</label>
	    </td>
	    <td>
            <div id="storeDiv"><select name="storeAbbrev" id="storeAbbrev"> <!-- Only selects SG currently !-->
                    <?php
                    $query = 'select storeAbbrev from stores where state=\'GA\'';
                    $result = mysql_query($query);
                    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                        echo "<option value = \"{$row['storeAbbrev']}\">{$row['storeAbbrev']}</option>";
                    }
                    ?>
                </select></div>
	    </td>
	    </tr>
	    <tr>
	    <td colspan="2">
            <input type="submit" value="Submit" class="submit"/>
	    </td>
	    </tr>
	    <tr>
	    <td colspan="2">
            <p>Please enter your credentials and click submit to continue.</p>
	    </td>
	    </tr>
	    </table>
        </form>
	<div id="infotext">
		<h2>Help</h2>
		<p>If you need help logging in please refer to the <a href="faq.html">FAQ</a> (Frequently Asked Questions).</p><br /><p>If you need additional help please email <a href="mailto:James.Weston@CellularSales.com">James Weston</a>.</p>
	</div>
    </div>
    <div id="maincontent">
	<h2>Welcome to the Cellular Sales South Georgia Trouble Ticket System (TTS)</h2>
	<p>Write some intro text here - ie what this site is, who should use it, etc...</p>
	<br />
	<h2>News</h2>
	<p>Put any news about system updates, scheduled maintenence,etc.</p>
    </div>
</body>
</html>
